package com.csk.zsk.compents.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.csk.zsk.commons.action.AjaxActionSupport;
import com.csk.zsk.commons.utils.encode.JsonBinder;
import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.compents.entity.News;
import com.csk.zsk.compents.service.NewsService;
@Controller
@Scope("prototype")
public class NewsAction extends AjaxActionSupport {
	private static final long serialVersionUID = 7995336055501590654L;
	private static JsonBinder binder = JsonBinder.buildNonDefaultBinder();
	@Autowired
	private NewsService newsService;
	
	private String newsId;
	private String type;
	private String length;
	
	
	
	public String getNewsId() {
		return newsId;
	}


	public void setNewsId(String newsId) {
		this.newsId = newsId;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}


	public String getLength() {
		return length;
	}


	public void setLength(String length) {
		this.length = length;
	}

	public NewsAction() {
		binder.setDateFormat("yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	 * 获取头条新闻
	 */
	public void getTop1(){
		News news = newsService.getTop1();
		String json = binder.toJson(news);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 通过ID获取新闻对象
	 */
	public void getNews(){
		News news = newsService.getNews(newsId);
		String json = binder.toJson(news);
		Struts2Utils.renderJson(json);
	}
	/**
	 * 通过类型获取新闻列表  时间倒序
	 */
	public void getNewsByTypeByTime(){
		List<News> newsList = newsService.getNewsByTypeByTime(type, Integer.parseInt(length));
		String json = binder.toJson(newsList);
		Struts2Utils.renderJson(json);
		
	}
	/**
	 * 获取全部新闻列表  时间倒序
	 */
	public void getNewsByTime(){
		List<News> newsList = newsService.getNewsByTime(Integer.parseInt(length));
		String json = binder.toJson(newsList);
		Struts2Utils.renderJson(json);
		
	}
	

}
